package com.bookRecommend.service.impl;

import com.bookRecommend.mapper.IScoreMapper;
import com.bookRecommend.model.Score;
import com.bookRecommend.service.IScoreService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScoreServiceImpl implements IScoreService {
    @Autowired
    IScoreMapper mapper;

    /**
     * 查询评分信息
     */
    @Override
    public List<Score> findAllScores() {
        return mapper.selectAllScores();
    }

    /**
     * 新增评分
     *
     * @param score
     */
    @Override
    public int addScore(Score score) {
        if (score == null) {
            return 0;
        }
        return mapper.insertScore(score);
    }

    /**
     * 修改评分
     */
    @Override
    public int modifyScore(Score score) {
        if (score == null) {
            return 0;
        }
        return mapper.updateScore(score);
    }

    /**
     * 删除评分
     */
    @Override
    public int removeScore(Integer id) {
        if (id == null) {
            return 0;
        }
        return mapper.deleteById(id);
    }

    @Override
    public PageInfo<Score> findPage(Integer n, Integer size) {
        if (n == null) {
            n = 1;
        }
        if (size == null) {
            size = 5;
        }
        PageHelper.startPage(n, size);
        return new PageInfo<>(mapper.selectAllScores());
    }

    @Override
    public Score findHotScoreByUserId(Integer userId) {
        return null;
    }

}